package com.google.code.avajhelpdesk.pages;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.apache.wicket.PageParameters;
import org.apache.wicket.markup.html.form.ChoiceRenderer;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.code.avajhelpdesk.components.formbuilder.CustomBeanEditor;
import com.google.code.avajhelpdesk.components.formbuilder.FormSubmitListener;
import com.google.code.avajhelpdesk.pages.issues.CreateIssue;
import com.google.code.avajhelpdesk.pages.users.UserListView;


/**
 * Homepage
 */
public class HomePage extends BasePage {
	
	private static final Logger logger = LoggerFactory.getLogger(HomePage.class);
	
	public static enum JobTitle {
		MASTER, EXPERT;
	}
	
	public static class EditableModel implements Serializable {

		private static final long serialVersionUID = 1L;

		private String firstName = "name";
		
		private String bigText;
		
		private JobTitle jobTitle;
		
		private boolean laBool;
		
		private int intVal;
		
		private long longVal;
		
		private float floatVal;
		
		private double doubleVal;
	
		private String choice;
		
		private List<String> choices = new ArrayList<String>();
		
		public String getFirstName() {
			return firstName;
		}
		
		public void setFirstName(String firstName) {
			this.firstName = firstName;
		}
	}

	private static final long serialVersionUID = 1L;
	
	private IModel model;
	
    /**
	 * Constructor that is invoked when page is invoked without a session.
	 * 
	 * @param parameters	
	 *            Page parameters
	 */
	public HomePage(final PageParameters parameters) {
		CustomBeanEditor beanEditFormPanel = new CustomBeanEditor("beanEditor", new Model(new EditableModel()), new FormSubmitListener() {
			
			public void onSubmit(Form<?> form, IModel<?> model) {
			
				System.err.println("ok");
			}
		});
		
		beanEditFormPanel
				.appendTextField("firstName")
						.setRequired(true);
		
		
		beanEditFormPanel.appendTextArea("bigText");
		
		Model choices = new Model(new ArrayList(Arrays.asList("one", "two", "three")));
		
		beanEditFormPanel.appendDropDownChoice("choice", choices, 
			new ChoiceRenderer());
		
		beanEditFormPanel.appendListMultipleChoice("choices", choices, new ChoiceRenderer());
		
		add(beanEditFormPanel);
    
		add(new BookmarkablePageLink("users", UserListView.class));
		add(new BookmarkablePageLink("issue", CreateIssue.class));
	}

	@Override
	protected String getPageTitle() {
		return "Home page";
	}
}
